package tt.dz.appserver.dao.ext;

import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import tt.dz.appserver.dao.base.BasisDao;
import tt.dz.appserver.entity.model.pub.Label;

/**
 * 标签管理Dao
 * 
 * @author USER001
 *
 */

@Repository
public class LabelDao extends BasisDao<Label> {

	public String findLatestLabelId() {

		Label labelmax = new Label();
		List<Label> labels = super.findExample(labelmax, 1, 1, "label_id", 0);

		if (labels.size() > 0) {
			return labels.get(0).getLabel_id();
		}
		return null;
	}

	/**
	 * 标签增加
	 */
	public int addLabel(Label label) {

		return super.save(label);
	}

	/**
	 * 标签删除
	 */
	public int delLabel(Label label) {

		return super.delete(label);
	}

	/**
	 * 标签更新
	 */
	public int updateLabel(Label label) {

		return super.update(label);
	}

	/**
	 * 标签查找
	 */
	public List<Label> findLabel() {
		return super.findListAutomaticOfClass(Label.class, null, null, null, null, null);
	}

	/**
	 * 查询桩友圈分享标签
	 * 
	 * @param sharesId
	 */
	@Cacheable(value = "shareLabel", key = "'sharesId'+#sharesId")
	public List<Label> findShareLabelBySharesId(String sharesId) {

		String sql = "SELECT label.label_id,label.label_type,label.label_name FROM as_pub_share_label AS shareLabel,as_pub_label AS label WHERE shareLabel.label_id = label.label_id and shareLabel.share_id=?";
		List<Label> labels = super.findDataAutomaticOfClassBySQL(new StringBuffer(sql), Label.class, null, null, sharesId);
		return labels;
	}
}
